/*
 * Created by JFormDesigner on Fri Jan 02 13:40:13 EET 2009
 */

package joodle.ui;
/**
 * This class represents the "About" button in the menu bar.
 */
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.net.URI;

import javax.swing.AbstractAction;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.MouseInputListener;

import joodle.si.ResourceManager;

@SuppressWarnings("serial")
public class AboutDialog extends JDialog implements MouseInputListener {
	
	public AboutDialog(Frame owner) {
		super(owner, ResourceManager.message("ABOUT"));
		initComponents();
	}
	/**
	 * Initialized the buttons and labels that will be take place in the "about" menu choice
	 */
	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		button1 = new JLabel();
		buttonBar = new JPanel();
		okButton = new JButton();

		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));

				//---- button1 ----
				//button1.setText("iconspedia.com");
				button1.setIcon(ResourceManager.makeIcon("us"));
				button1.addMouseListener(this);
				button1.addMouseMotionListener(this);
				contentPanel.add(button1);
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				//((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 180};
				//((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {0.0, 1.0};

				//---- okButton ----
				okButton.setAction(new AbstractAction("Visit us on the Web") {
					/**
					 * @see MouseInputListener#actionPerformed(ActionEvent e)
					 */
					@Override
					public void actionPerformed(ActionEvent e) {
						AboutDialog.this.dispose();
						try {
							Desktop.getDesktop().browse(
								new URI("http://www.ug.bcc.bilkent.edu.tr/~m_ozdal/Site/Home.html"));
						}
						catch(Exception be) {}
					}
					
				});
				logoLabel = new JLabel(ResourceManager.makeIcon("logo_sm"));
				descLabel = new JLabel(ResourceManager.message("us"));
				//descLabel.setMinimumSize(new Dimension(0, 160));
				
				buttonBar.add(logoLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						new Insets(0, 0, 0, 0), 10, 0));
				buttonBar.add(descLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						new Insets(0, 0, 0, 0), 0, 0));
				buttonBar.add(okButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
						GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
					new Insets(0, 0, 0, 0), 0, 0));

				
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		setResizable(false);

		contentPane.add(dialogPane, BorderLayout.CENTER);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JLabel button1;
	private JPanel buttonBar;
	private JButton okButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	
	private JLabel logoLabel;
	private JLabel descLabel;
	/**
	 * @see MouseInputListener#mouseClicked(MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * @see MouseInputListener#mouseEntered(MouseEvent)
	 */
	@Override
	public void mouseEntered(MouseEvent e) {
		showMemberInfo((int) e.getPoint().getX() / 113);
		//okButton.setVisible(false);
	}
	/**
	 * @see MouseInputListener#mouseExited(MouseEvent)
	 */
	@Override
	public void mouseExited(MouseEvent e) {
		showMemberInfo(-1);
		//okButton.setVisible(true);
	}
	/**
	 * @see MouseInputListener#mousePressed(MouseEvent)
	 */
	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * @see MouseInputListener#mouseReleased(MouseEvent)
	 */
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * @see MouseInputListener#mouseDragged(MouseEvent)
	 */
	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * @see MouseInputListener#mouseMoved(MouseEvent e)
	 */
	@Override
	public void mouseMoved(MouseEvent e) {
		showMemberInfo((int) e.getPoint().getX() / 113);
	}
	/**
	 * Calls information about members
	 * @param i holds the number of the member
	 */
	private void showMemberInfo(int i) {
		String s = i < 5 && i >= 0 ? "member" + i : "us";
		button1.setIcon(ResourceManager.makeIcon(s));
		descLabel.setText(ResourceManager.message(s));
	}
}
